
module.exports=function (done) {
	$.checkLogin=async function (req,res,next) {
		if (!req.session.user) {
			return next(new Error('please login'));
		}
		next();
	}
	$.checkTopicAuthor=async function (req,res,next) {
		const topic=await $.method('topic.get').call({_id: req.params.topic_id});
		if (!topic)
			return next(new Error(`topic ${req.params.topic_id} does not exist!`));
		if (req.session.user && topic._id.toString != req.session.user._id.toString()) {
			return next(new Error(`you have not right to eidt topic ${req.params.topic_id}`));
		}
		next();
	}
	done();
}